package com.banmao.CarlCamp.Day08;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Offer58_Carl {

    public String reverseLeftWords(String s, int n) {
        char[] chars = s.toCharArray();
        reverse(chars, 0, chars.length - 1);
        reverse(chars, 0, chars.length - 1 - n);
        reverse(chars, chars.length - n, chars.length - 1);
        return new String(chars);
    }

    public void reverse(char[] chars, int left, int right) {
        while (left < right) {
            chars[left] ^= chars[right];
            chars[right] ^= chars[left];
            chars[left] ^= chars[right];
            left++;
            right--;
        }
    }

    public static void main(String[] args) {

        char[] chars = new char[]{'a', 'b'};

        chars[0] ^= chars[1];
        chars[1] ^= chars[0];
        chars[0] ^= chars[1];

        log.info("{}", chars);
    }

}
